// INCLUDES --------------------------------------------------------------------
#include "ray.h"

// FUNCTIONS -------------------------------------------------------------------

/* GENERAL:
   d    -> destination
   s    -> source
   size -> array size (0,1 for single elements)

   r    -> arbitrary ray
   k    -> floating point scalar
*/

static int i;

// clear to origin:[0,0,0,1], direction:[0,0,-1,1]
void rClear(ray *r, ui32 size)
{
  GUARD_NULL("rClear *r", r);

  if (size == 0) size = 1;
  
  for (i = 0; i < size; i++) vClear(&r->c[0], 2);
  r->d.z = -1.0f;
};

// clone ray
void rCopy(ray *d, ray *s, ui32 size)
{
  GUARD_NULL("rCopy *d", d);
  GUARD_NULL("rCopy *s", s);

  if (size == 0) size = 1;

  memcpy(d, s, sizeof(ray)*size);
};

/* the vector equation of a line through some point o and parallel to
   another vector d is defined as:

   p = o + kd

   where:

   o    is the origin of the line
   k    being a scalar
   d    a vector parallel to the line

   resulting in every real value of scalar t generating a real point p
   on the line.

*/
void rPoint(vertex4 *d, ray *r, fp k)
{
  vMul(d, &r->d, k);
  vAddTo(d, &r->o);
};
